﻿using System.IO;
using System.Text;

namespace Als.Utils.Pay.WeixinPay
{
    public static class TenPayV3
    {
        public static string Refund(string data, string cert, string password)
        {
            string url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
            byte[] buffer = (data == null) ? new byte[0] : Encoding.UTF8.GetBytes(data);
            MemoryStream postStream = new MemoryStream();
            postStream.Write(buffer, 0, buffer.Length);
            postStream.Seek(0L, SeekOrigin.Begin);
            return RequestUtility.HttpPost(url, cert, password, null, postStream, null, null, null);
        }

        public static string transfers(string data, string cert, string password)
        {
            string url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";
            byte[] buffer = data == null ? new byte[0] : Encoding.UTF8.GetBytes(data);
            MemoryStream memoryStream = new MemoryStream();
            memoryStream.Write(buffer, 0, buffer.Length);
            memoryStream.Seek(0L, SeekOrigin.Begin);
            return RequestUtility.DoPost(url, data, password, cert);
        }

        public static string Unifiedorder(string data)
        {
            string url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
            byte[] buffer = (data == null) ? new byte[0] : Encoding.UTF8.GetBytes(data);
            MemoryStream postStream = new MemoryStream();
            postStream.Write(buffer, 0, buffer.Length);
            postStream.Seek(0L, SeekOrigin.Begin);
            return RequestUtility.HttpPost(url, null, postStream, null, null, null);
        }
    }
}
